package com.um.jdy.app.device.manager;


import com.um.jdy.app.device.entity.vo.HomePackageVO;
import com.um.jdy.common.base.enums.YesOrNo;
import com.um.jdy.common.platform.entity.po.App;
import com.um.jdy.common.platform.entity.po.AppPackage;
import com.um.jdy.common.platform.entity.po.AppSetting;
import com.um.jdy.common.platform.entity.vo.AppPackageVO;
import com.um.jdy.common.platform.service.AppPackageService;
import com.um.jdy.common.platform.service.AppService;
import com.um.jdy.common.platform.service.AppSettingService;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.utils.UMBeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @Title
 * @Description
 * @Author renjunwei
 * @Date 2023/5/22 10:37
 */
@Slf4j
@Service
public class AppPackageManager {

    @Autowired
    AppPackageService appPackageService;

    @Autowired
    AppSettingService appSettingService;

    @Autowired
    AppService appService;

    /**
     * 查询平台可以使用的设备类型
     * @return
     */
    public Response<HomePackageVO> getAppPackage() {
        AppPackage appPackage = appPackageService.getEntity("com_id",appPackageService.getComId());
        if (appPackage == null) {
            appPackage = new AppPackage();
            appPackage.setOpenEb(YesOrNo.No.name());
            appPackage.setOpenEbox(YesOrNo.No.name());
            appPackage.setOpenEv(YesOrNo.No.name());
            appPackage.setOpenPb(YesOrNo.No.name());
        }

        HomePackageVO packageVO = UMBeanUtils.copyBean(appPackage,HomePackageVO.class);

        App app = appService.getEntity("com_id", appSettingService.getComId());
        if(app.getMallEntranceEnable().equals(YesOrNo.No.name())){
            packageVO.setOpenMall(YesOrNo.No.name());
        }

        AppSetting appSetting = appSettingService.getEntity("com_id", appSettingService.getComId());
        if(appSetting != null){
            packageVO.setShareIcon(appSetting.getShareIcon());
            packageVO.setShareTitle(appSetting.getShareTitle());
        }


        return Response.success(packageVO);
    }

}
